﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraBars.Docking2010.Views.WindowsUI;
using DevExpress.XtraEditors;
using EduFormManager.Models;
using EduFormManager.Utilities;
using Message = EduFormManager.Models.Message;

namespace EduFormManager.Forms.UserControls
{
    public partial class XtraBaseControl : XtraUserControl
    {
        public enum Type
        {
            Form,
            Component
        }

        protected static MarqueeProgressDialog ProgressDialog = new MarqueeProgressDialog();
        protected List<Entity> _editedList;

        protected Type _controlType;
        public XtraBaseControl()
        {
            InitializeComponent();
        }
        public XtraBaseControl(WindowsUIView view)
        {
            InitializeComponent();
            this.View = view;
            
            _editedList = new List<Entity>();

            _controlType = Type.Component;
        }

        public virtual Type ControlType
        {
            get
            {
                return _controlType;
            }
            set 
            {
                _controlType = value;
            }
        }

        public DialogResult WarnAboutSavingChanges()
        {
            return this.ShowFlyoutMessageBox("Подтверждение", "Сохранить изменения?", FlyoutCommand.Yes, FlyoutCommand.No, FlyoutCommand.Cancel);
        }

        public DialogResult ShowFlyoutMessageBox(string caption, string msg, params FlyoutCommand[] commands)
        {
            Flyout fly = View.ContentContainers.FindFirst(x => x is Flyout && x.Caption == "Сообщение") as Flyout;
            if (View != null && fly != null)
            {
                return GuiUtility.ShowFlyoutMessage(View, fly, caption, msg, commands);
            }
            else
            {
                return MessageBox.Show(msg, caption, MessageBoxButtons.OK);
            }
        }

        public WindowsUIView View
        {
            get;
            set;
        }

        public virtual IList<Allform> DataSourceAllform
        {
            set
            {
                allformBindingSource.DataSource = (object)value;
            }
            get
            {
                return allformBindingSource.DataSource as IList<Allform>;
            }
        }

        public virtual IList<AllformType> DataSourceAllformType
        {
            set
            {
                allformTypeBindingSource.DataSource = (object)value;
            }
            get
            {
                return allformTypeBindingSource.DataSource as IList<AllformType>;
            }
        }

        public virtual IList<TemplatedFormData> DataSourceTemplatedFormData
        {
            set
            {
                templatedFormDataBindingSource.DataSource = value;
            }
        }

        public virtual  IList<Query> DataSourceQuery
        {
            set
            {
                queryBindingSource.DataSource = value;
            }
        }
        public virtual IList<EduOrg> DataSourceEdu
        {
            set
            {
                eduOrgBindingSource.DataSource = new BindingList<EduOrg>(value);
            }
        }
        public virtual IList<Municipality> DataSourceMunicipality
        {
            set
            {
                municipalityBindingSource.DataSource = value;
            }
        }
        public virtual IList<EduOrgType> DataSourceEduType
        {
            set
            {
                eduOrgTypeBindingSource.DataSource = value;
            }
        }
        public virtual IList<EduOrgKind> DataSourceEduKind
        {
            set
            {
                eduOrgKindBindingSource.DataSource = value;
            }
        }
        public virtual IList<Message> DataSourceMessage
        {
            set
            {
                messageBindingSource.DataSource = value;
            }
        }
        protected virtual void New(Document doc) { }
        protected virtual bool CanNew(Document doc) { return true; }
        protected virtual void Save(Document doc) { }
        protected virtual bool CanSave(Document doc) { return true; }
        protected virtual void Remove(Document doc) { }
        protected virtual bool CanRemove(Document doc) { return true; }
        protected virtual void UpdateData()
        {
            //Utilities.GuiUtility.BuildFormTiles(LoggedInEdu, View);
        }
    }
}
